package com.lc.redis.redisTemplate;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.Set;

@SpringBootTest
public class ZSetType {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 排名
     */
    @Test
    public void testSearch(){
        //将其之前的关注数量放入ZSet里面当score
        redisTemplate.opsForZSet().add("user:lc:ranking","arcticle:1",redisTemplate.opsForSet().members("article:1").size());
        redisTemplate.opsForZSet().add("user:lc:ranking","arcticle:2",3);
        redisTemplate.opsForZSet().add("user:lc:ranking","arcticle:3",6);
        redisTemplate.opsForZSet().add("user:lc:ranking","arcticle:4",5);
        Set range = redisTemplate.opsForZSet().range("user:lc:ranking", 0, 5);
        System.out.println(range);
    }

    /**
     * 添加点赞次数
     */
    @Test
    public void testAdd(){
        redisTemplate.opsForZSet().incrementScore("user:lc:ranking","arcticle:3",1);
        Set range = redisTemplate.opsForZSet().rangeWithScores("user:lc:ranking", 0, 5);
        System.out.println(range);
    }

}
